//
//  JBWBaseViewController.swift
//  新浪微博
//
//  Created by 季伯文 on 2017/6/29.
//  Copyright © 2017年 bowen. All rights reserved.
//

import UIKit

class JBWBaseViewController: UIViewController {

    //判断是否登录
    let isLogin: Bool = JBWOAuthViewModel.share.isLogin
    //全局访客视图
    var visitorView: JBWVisitorView?
    
    override func loadView(){
        
        if !isLogin {
            setupVisitorView()
        } else {
            view = tableView
//            super.loadView()
        }
    }
    
    //监听事件
    @objc private func loginClick(){
//        print("监听按钮点击弹出控制器gogogo")
        let oautoVC = JBWOAuthViewController()
        let nav = JBWNavigationController(rootViewController: oautoVC)
        
        //模态弹出
        present(nav, animated: true, completion: nil)
        
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupNav()
    }
    
    //设置访客视图
    private func setupVisitorView(){
        
        //实例化JBWVisitorView
        visitorView = JBWVisitorView()
        //实例化闭包
        visitorView?.closure = {[weak self]in
            
            //执行闭包
            self?.loginClick()
        }
        view = visitorView
        setupNav()
    }
    
    //设置导航
    private func setupNav(){
    
        navigationItem.leftBarButtonItem = UIBarButtonItem(imgName: nil, title: "注册", target: self, action: #selector(loginClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(imgName: nil, title: "登录", target: self, action: #selector(loginClick))
    
    }
    
    //列表
    lazy var tableView: UITableView = {
    let view = UITableView()
    return view
    
    }()
}
